package cn.javass.dp.proxy.demo3;

import cn.javass.dp.proxy.demo1.IUserDao;
import cn.javass.dp.proxy.demo1.UserDao;

import java.lang.reflect.Proxy;

/**
 * **JDK 动态代理有一个最致命的问题是其只能代理实现了接口的类。**
 */
public class JdkProxyFactory {

    public static Object getProxy(Object target) {
        return Proxy.newProxyInstance(target.getClass().getClassLoader()
                , target.getClass().getInterfaces()
                , new DebugInvocationHandler(target));
    }

    public static void main(String[] args) {
        IUserDao dao = new UserDao();
        IUserDao proxy = (IUserDao)JdkProxyFactory.getProxy(dao);
        proxy.save();
    }


}
